<template>
  <Card>

    <div class="flexCSB">
      	<Select filterable v-model="appId" @on-change="changeAppid">
      		<template v-for="item in appIdList">
      			<Option :value="item.consumerMiniAppId">{{item.miniAppName}}</Option>
      		</template>
  		</Select>
    </div>

    <Table style="margin-top:10px" class="table" :loading="loading1" highlight-row :columns="columns" :data="data"></Table>

    <Modal v-model="modal" title="体验版二维码" width="50">
		<img style="width:100%" :src="src"></img>
		<div slot="footer"></div>
	</Modal>

  </Card>
</template>

<script>
	export default {
    	data() {
      		return {
      			modal: false,
      			loading1: false,
      			loading2: false,
      			src: '',
      			columns: [
      				{ title: "appId", key: "appId", align: "center",minWidth: 200},
      				{ title: "版本", key: "appVersion", align: "center",minWidth: 200},
      				{ title: "构建状态", key: "createStatus2", align: "center",minWidth: 200},
      				{ title: "是否是体验版", key: "experienceFlag2", align: "center",minWidth: 200},
      				{ title: "小程序版本状态", key: "status2", align: "center",minWidth: 200},
      				{ title: "模板小程序appid", key: "templateId", align: "center",minWidth: 200},
      				{ title: "模板小程序版本", key: "templateVersion", align: "center",minWidth: 200},
      				{
				        title: "操作",
				        align: "center",
				        minWidth: 400,
				        render: (h, params) => {
				            return h(
				              	"div",
				              	{
				                	style: {
				                  		display: 'flex'
				                	}
				              	},
				              	[
				                	h("Button",{
				                    	props: {
				                      		type: "warning"
				                    	},
				                    	style: {
				                      		display: !params.row.experienceFlag ? "block" : "none",
				                      		'marginRight': '10px'
				                    	},
				                    	on: {
				                      		click: () => {
				                        		this.yes(params);
				                      		}
				                    	}
				                  	},"设为体验版"),
				                  	h("Button",{
				                    	props: {
				                      		type: "warning"
				                    	},
				                    	style: {
				                      		display: params.row.experienceFlag ? "block" : "none",
				                      		'marginRight': '10px'
				                    	},
				                    	on: {
				                      		click: () => {
				                        		this.no(params);
				                      		}
				                    	}
				                  	},"取消体验版"),
				                  	h("Button",{
				                    	props: {
				                      		type: "error"
				                    	},
				                    	style: {
				                      		display: "block",
				                      		'marginRight': '10px'
				                    	},
				                    	on: {
				                      		click: () => {
				                        		this.code(params);
				                      		}
				                    	}
				                  	},"体验版二维码"),
				                
				            	]
				        	)
				        }
				    }
      			],
      			data: [],
      			appId: '',
      			appIdList: [],

      		}
      	},
      	created(){
      		this.getIsvMarketOrder()
      	},
      	methods:{
      		changeAppid(data){
      			this.appId = data
      			this.getIsvMiniVersionUploadList()
      		},
      		getIsvMarketOrder(){
      			this.loading1 = true;
			    this.$http("/stage/appletBuild/getIsvMarketOrder", {
			    	current: 1,
			    	size: 1000
			    }, "post", res => {
			        if (res.data.code == 200) {
			        	this.appIdList = res.data.data.records
			        	this.appId = res.data.data.records[0].consumerMiniAppId
			        	this.getIsvMiniVersionUploadList()
			        }
			    })
      		},
      		getIsvMiniVersionUploadList(){
      			this.loading1 = true;
			    this.$http("/stage/appletBuild/getIsvMiniVersionUploadList", {
			    	appId: this.appId
			    }, "post", res => {
			    	this.loading1 = false
			        if (res.data.code == 200) {
			        	for(let i=0;i<res.data.data.length;i++){
			        		if(res.data.data[i].createStatus == 0){res.data.data[i].createStatus2 = '构建排队中'}
			        		if(res.data.data[i].createStatus == 1){res.data.data[i].createStatus2 = '正在构建'}
			        		if(res.data.data[i].createStatus == 2){res.data.data[i].createStatus2 = '构建成功'}
			        		if(res.data.data[i].createStatus == 5){res.data.data[i].createStatus2 = '构建超时'}
			        		if(res.data.data[i].createStatus == 6){res.data.data[i].createStatus2 = '版本创建成功'}

			        		if(res.data.data[i].status == 'INIT'){res.data.data[i].status2 = '开发中'}
			        		if(res.data.data[i].status == 'AUDITING'){res.data.data[i].status2 = '审核中'}
			        		if(res.data.data[i].status == 'WAIT_RELEASE'){res.data.data[i].status2 = '审核通过'}
			        		if(res.data.data[i].status == 'AUDIT_REJECT'){res.data.data[i].status2 = '审核驳回'}
			        		if(res.data.data[i].status == 'RELEASE'){res.data.data[i].status2 = '已上架'}
			        		if(res.data.data[i].status == 'GRAY'){res.data.data[i].status2 = '灰度中'}
			        		if(res.data.data[i].status == 'OFFLINE'){res.data.data[i].status2 = '下架'}


			        		if(res.data.data[i].experienceFlag){res.data.data[i].experienceFlag2 = '体验版'}else{res.data.data[i].experienceFlag2 = '非体验版'}


			        	}
			        	this.data = res.data.data
			        }
			    })
      		},
      		yes(data){
      			console.log(data.row.id)
      			this.$http("/stage/appletBuild/experienceCreate", {
			    	appId: data.row.appId,
			    	app_version: data.row.appVersion,
			    }, "post", res => {
			        if (res.data.code == 200) {
			        	this.$Message.success("设定成功");
			        	this.getIsvMiniVersionUploadList()
			        }else{
			        	this.$Message.error(res.data.msg);
			        }
			    })
      		},
      		no(data){
      			this.$http("/stage/appletBuild/experienceCancel", {
			    	appId: data.row.appId,
			    	app_version: data.row.appVersion,
			    }, "post", res => {
			        if (res.data.code == 200) {
			        	this.$Message.success("取消成功");
			        	this.getIsvMiniVersionUploadList()
			        }else{
			        	this.$Message.error(res.data.msg);
			        }
			    })
      		},
      		code(data){
      			this.$http("/stage/appletBuild/experienceQuery", {
			    	appId: data.row.appId,
			    	app_version: data.row.appVersion,
			    }, "post", res => {
			    	// res.data = {
			    	// 	code: 200,
					   //  data: {
					   //      expQrCodeUrl: "https://mobilecodec.alipay.com/show.htm?code=s4x16472etl5nmnytnyjz38"
					   //  }
			    	// }
			        if (res.data.code == 200) {
			        	this.modal = true
			        	this.src = res.data.data.expQrCodeUrl
			        }else{
			        	this.$Message.error(res.data.msg);
			        }
			    })
      		},
      	

      	},

  	}
</script>

<style scoped>
	
</style>